<?php

namespace app\common\model\assistant;

use think\Model;


class Withdraw extends Model
{

    

    CONST STATUS_BACK = 2;
    CONST STATUS_INIT = 0;
    CONST STATUS_SUCCESS = 1;

    const STATUS_ARRAY = [
        self::STATUS_BACK => '已驳回',
        self::STATUS_INIT => '待审核',
        self::STATUS_SUCCESS => '已通过',
    ];
    const TYPE_WECHAT = 'wechat';
    const TYPE_ALIPAY = 'alipay';
    const TYPE_ARRAY = [
        self::TYPE_WECHAT => '微信',
        self::TYPE_ALIPAY => '支付宝',
    ];
    // 表名
    protected $name = 'assistant_withdraw';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'status_text',
        'review_status_text',
        'is_system_text',
        'create_time_text',
        'update_time_text'
    ];
    

    
    public function getTypeList()
    {
        return ['wechat' => __('Type wechat'), 'alipay' => __('Type alipay')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getReviewStatusList()
    {
        return ['0' => __('Review_status 0'), '1' => __('Review_status 1'), '2' => __('Review_status 2')];
    }

    public function getIsSystemList()
    {
        return ['0' => __('Is_system 0'), '1' => __('Is_system 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getReviewStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['review_status']) ? $data['review_status'] : '');
        $list = $this->getReviewStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsSystemTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_system']) ? $data['is_system'] : '');
        $list = $this->getIsSystemList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function assistant()
    {
        return $this->belongsTo('app\admin\model\Assistant', 'assistant_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
